/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.Properties;
import util.file.FileUtil;

/**
 *
 * @author Rdelacruz
 */
public class PropertiesUtil {
    

    
    public static Properties getProperties(String ruta) throws IOException {
        Properties properties = new Properties();
        properties.load(FileUtil.getResourceAsStreamFromDefaultPackage(ruta));
        return properties;
    }
    
    //Problema: Backslash en Properties
    //http://stackoverflow.com/questions/5784895/java-properties-backslash
    //http://stackoverflow.com/questions/9371288/java-properties-getting-file-path
    public static Properties getPropertiesSinBackSlash(String ruta) throws IOException {
        InputStream is = FileUtil.getResourceAsStreamFromDefaultPackage(ruta);
        if(is==null)
            return null;
        String propertyFileContents = FileUtil.replaceInStreamToString(is,"\\","\\\\");
        Properties props = new Properties();
        props.load(new StringReader(propertyFileContents));
        return props;
    }
}
